check number of triplets for given sum in array